package com.ly.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ly.bean.EasybuyProduct;
import com.ly.bean.EasybuyProductComment;
import com.ly.bean.EasybuyProductImages;
import com.ly.mapper.EasybuyProductCommentMapper;
import com.ly.mapper.EasybuyProductImagesMapper;
import com.ly.mapper.EasybuyProductMapper;
import com.ly.service.ProductCommentsService;
import com.ly.service.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
@author 李岩
@date 2021/12/14-13:52
@describe
*/
@Component
@Service(interfaceClass = ProductCommentsService.class)
public class ProductCommentsServiceImpl implements ProductCommentsService {
    private final Logger logger= LoggerFactory.getLogger(ProductCommentsServiceImpl.class);
    private ProductCommentsServiceImpl(){
        System.out.println("ProductCommentsServiceImpl   商品的service层");
    }
    @Autowired
    private EasybuyProductCommentMapper productCommentMapper;
    /**
     *根据商品id查询该商品的评论信息
     */
    @Override
    public PageInfo<EasybuyProductComment> selectProductCommentsKey(Integer pid,String pageNum) throws Exception {
        Integer pageNumInt=1;
        Integer pageSizeInt=3;
        if (pageNum!=null && !"".equals(pageNum)){
            pageNumInt=Integer.valueOf(pageNum);
        }
        PageHelper.startPage(pageNumInt,pageSizeInt);
        List<EasybuyProductComment> list = productCommentMapper.selectProductCommentsKey(pid);
        PageInfo<EasybuyProductComment> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
    //根据商品id统计该商品的评论占比
    @Override
    public Map<String, Object> selectLevelCommentNUmBypid(Integer pid) throws Exception {
        return productCommentMapper.selectLevelCommentNUmBypid(pid);
    }
}
